import pandas as pd
import plotly.express as px
wb_df = pd.read_csv('../data/iunc_whales_only.csv')
custom_order = [
"Critically Endangered",
"Endangered",
"Vulnerable",
"Near Threatened",
"Least Concern",
"Data Deficient"
]
wb_df['redlistCategory'] = pd.Categorical(
wb_df['redlistCategory'],
categories=custom_order,
ordered=True
)
color_map = {
"Critically Endangered": "#3a5ba0",
"Endangered": "#3a5ba0",
"Vulnerable": "#3a5ba0",
"Near Threatened": "#3a5ba0",
"Least Concern": "#3a5ba0",
"Data Deficient": "#999999"
}
fig = px.histogram(
wb_df,
x="redlistCategory",
color="redlistCategory",
category_orders={"redlistCategory": custom_order},
labels={
"redlistCategory": "Classification",
"count": "Amount"
},
color_discrete_map=color_map
)
fig.update_layout(
title={
'text': '<b>Endangerment Classifications for Whale Species</b>',
'x': 0.5,
'xanchor': 'center',
'font': {
'color': '#0a2463',
}
},
height=600,
xaxis={
'title': 'Endangerment Classification (Red List Standards)',
'categoryorder': 'array',
'categoryarray': custom_order
},
yaxis={
'title': 'Amount of Whale Species'
},
margin={'l': 30, 'b': 130, 'r': 30, 't': 30},
showlegend=False,
)
fig.add_annotation(x=0, y=-0.24,
xref="paper", yref="paper",
showarrow=False,
align='left',
xanchor='left', yanchor='bottom',
text="Red List Endangerment Classifications for all recorded whale species. <br>" + \
'Hover over bars to see specific count of whale species per category.<br>' + \
'Species lacking enough data are marked Data Deficient.')
fig.update_annotations(
font=dict(color='#0a2463')
)
fig.show()